﻿using System.Windows.Forms;
using Client.Controllers;
using Client.Interfaces;
using Global.Impl.Server;

namespace Client
{
    public partial class MainWindow : Form, IMainView
    {
        private IMainController _controller;

        public MainWindow()
        {
            InitializeComponent();

            _controller = new MainController(this);
            _controller.Start();
        }

        #region IMainWindow Members

        public Panel Panel 
        { 
            get { return pMain; } 
            set { pMain = value; }
        }

        internal IMainController Controller
        {
            get { return _controller; }
            set { _controller = value; }
        }

        public void OpenNewChatWindows(ChatRequest request)
        {
            MethodInvoker invoker = delegate
            {
                ChatWindow chatWindow = new ChatWindow(_controller, request.Endpoint, request.Password);
                chatWindow.Show();
            };
            this.Invoke(invoker);
        }
        #endregion

        #region UI events
        private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            _controller.Close();
        }
        #endregion
    }
}
